﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class EditorMode : MonoBehaviour
{
    public WeaponSwitchPanel m_WeaponSwitcher;
    public GameObject m_Tip;
    void Start()
    {
    }


    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if(!UtilsUnity.IsOnUI(Input.mousePosition))
            {
                if (!EventSystem.current.IsPointerOverGameObject() && m_WeaponSwitcher != null && !m_WeaponSwitcher.m_WeaponDescriptionPanel.activeSelf)
                    m_WeaponSwitcher.SetHidden(true);

                int layerMask = 1 << 10;
                RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 100000, layerMask);
                if (hit.collider != null)
                {
                    var obj = hit.collider.gameObject;
                    var weaponSlot = obj.GetComponent<WeaponSlot>();
                    if (weaponSlot && m_WeaponSwitcher != null)
                    {
                        m_WeaponSwitcher.updateItemList(weaponSlot);
                        m_WeaponSwitcher.SetHidden(false);
                    }
                }
            }
        }

        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if (m_WeaponSwitcher.m_WeaponDescriptionPanel.activeSelf)
                m_WeaponSwitcher.m_WeaponDescriptionPanel.SetActive(false);
            else
                m_WeaponSwitcher.gameObject.SetActive(false);
        }
    }

    public void setEnabled(bool enabled2)
    {
        enabled = enabled2;
        if (m_Tip)
            m_Tip.SetActive(enabled);
    }
}
